﻿using System;
using ZFine.Application.Gas;
using ZFine.Application.SystemManage;
using ZFine.Code;
using ZFine.Domain.Entity.Gas;
using ZFine.Domain.Entity.SystemManage;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;

namespace ZFine.Web.Areas.Gas.Controllers
{
    public class RollOutRecordController : ControllerBase
    {
        private SchoolApp schoolApp = new SchoolApp();
        private RollOutRecordApp rollOutRecordApp = new RollOutRecordApp();

        [HttpGet]
        [HandlerAuthorize(ignore: false)]
        public override ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize(ignore: false)]
        public override ActionResult Form()
        {
            return View();
        }
        [HandlerAuthorize(ignore: false)]
        public override ActionResult Details()
        {
            return View();
        }
        [HandlerAuthorize(ignore: false)]
        public ActionResult Update()
        {
            return View();
        }
        [HandlerAuthorize(ignore: false)]
        public ActionResult Upload()
        {
            return View();
        }
        [HandlerAuthorize(ignore: false)]
        public ActionResult EduCheckIndex()
        {
            return View();
        }
        [HandlerAuthorize(ignore: false)]
        public ActionResult EduCheckForm()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination)
        {
            string schoolAccount = OperatorProvider.Provider.GetCurrent().UserCode;
            SchoolEntity schoolEntity = schoolApp.GetFormBySchoolAccount(schoolAccount);
            List<RollOutRecordEntity> l_rollOutRecord = rollOutRecordApp.GetIQueryable(schoolEntity.F_Id,"","").ToList();
            var data = new
            {
                page = pagination.page,//当前页  1  2 3 之类
                records = pagination.records,//总条数  这里应该是18
                rows = l_rollOutRecord,//分页的数据
                total = pagination.total,//页数
            };
            return Content(data.ToJson());
        }
        //修改页数据
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJsonForUpdate(string keyValue)
        {
            RollOutRecordEntity data = rollOutRecordApp.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(RollOutRecordEntity rollOutRecordEntity, string keyValue,string eduFlag)
        {
            string schoolAccount = OperatorProvider.Provider.GetCurrent().UserCode;
            SchoolEntity schoolEntity = schoolApp.GetFormBySchoolAccount(schoolAccount);
            if (null != schoolEntity)
            {
                rollOutRecordEntity.SchoolId = schoolEntity.F_Id;
            }
            if("1" != eduFlag)
            {
                rollOutRecordEntity.status = "1";
            }
            rollOutRecordApp.SubmitForm(rollOutRecordEntity, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize(ignore: false)]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            rollOutRecordApp.Del(keyValue);
            return Success("删除成功。");
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJsonByEdu(Pagination pagination,string schoolId, string classValue, string status)
        {
            List<RollOutRecordEntity> l_rollOutRecord = rollOutRecordApp.GetIQueryable(schoolId, classValue, status).ToList();
            var data = new
            {
                page = pagination.page,//当前页  1  2 3 之类
                records = pagination.records,//总条数  这里应该是18
                rows = l_rollOutRecord,//分页的数据
                total = pagination.total,//页数
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult MultiUpdate(string selId)
        {
            if (!string.IsNullOrEmpty(selId))
            {
                string[] arrId = selId.Split(',');
                foreach (var keyValue in arrId)
                {
                    RollOutRecordEntity data = rollOutRecordApp.GetForm(keyValue);
                    data.status = "3";
                    //更新数据
                    rollOutRecordApp.SubmitForm(data, keyValue);
                }
                return Success("操作成功。");
            }
            return Success("操作失败。");
        }
    }
}
